<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/19
 * Time: 21:57
 */

namespace app\api\model;

class Theme extends BaseModel
{
    //隐藏字段
    protected $hidden = ['update_time', 'delete_time', 'create_time', 'from'];
    //获取器
    protected function getUrlAttr($value, $data)
    {
        return $this -> getImgPrefix($value, $data);
    }
    //关联img表
    public function topicImg()
    {
        return $this -> belongsTo('Image', 'topic_img_id', 'id');
    }
    public function headImg()
    {
        return $this -> belongsTo('Image', 'head_img_id', 'id');
    }
    //关联product表
    public function products()
    {
        return $this -> belongsToMany('Product', 'theme_product', 'product_id', 'theme_id');
    }
    //获取商品表数据
    public function getComplexOne($id = '')
    {
        return self::with(['products', 'topicImg', 'headImg']) -> find($id);
    }
    //获得theme和图片信息
    public function getSimpleList($ids = '')
    {
        return self::with('topicImg', 'headImg') -> select($ids);
    }
}